package com.dkm.ec.product.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dkm.ec.home.persistence.entity.HomeEntityPo;
import com.dkm.ec.home.repository.HomeEntityRepository;
import com.dkm.ec.product.domain.ProdTrack;
import com.dkm.ec.product.persistence.dao.ProdTrackDao;
import com.dkm.ec.product.persistence.entity.ProdTrackPo;
import com.dkm.ec.product.repository.ProdTrackRepository;
import com.dkm.ec.product.service.ProdTrackService;

@Service
public class ProdTrackServiceImpl implements ProdTrackService{
	@Resource
	private ProdTrackRepository prodTrackRepository;
	@Resource
	private HomeEntityRepository homeEntityRepository;
	
	@Resource
	private ProdTrackDao prodTrackDao;
	public void saveTrack(List<ProdTrackPo> prodTrackPos) {
		for(ProdTrackPo po:prodTrackPos){
				ProdTrack prodTrack = prodTrackRepository.newInstance(po);
				prodTrack.save();	
				}
		
	}
	@Override
	public List<HomeEntityPo> findAllByProdTrack(List<ProdTrackPo> prodTrackPos) {
		if(prodTrackPos==null||prodTrackPos.size()==0){
		return null;
		}else{
			
			StringBuffer sb = new StringBuffer("");
			Integer count =0;
			for(ProdTrackPo prodTrackPo:prodTrackPos){
				if(count!=0)sb.append(",");
				else{
					sb.append("(");
					count++;
				}
				sb.append("'");
				sb.append(prodTrackPo.getProdId());
				sb.append("'");
			}
			if(count>0){
				sb.append(")");	
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("whereSql", "p.id_ in "+sb.toString());
				return homeEntityRepository.findForSelector(map);
			}
			
			return null;
		}
	}
	
	

	
}
